using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace ColladaDotNet.OpenTKMapping
{
	public class TextureColorSource : ColorSource
	{
		public override void Bind(EffectCommonProfile args)
		{
			base.Bind(args);

			var p = args.GetNewParam(Collada.texture);
			if (p != null)
			{
				var sampler = p.Sampler2D;
				if (sampler != null)
				{
					var src = args.GetNewParam(sampler.Source);
					if (src != null)
					{
						var surface = src.Surface;
						if (surface != null)
						{
							var i = Document.Images[surface.InitFrom];
							i.Bind(Collada.texcoord);
						}
					}
				}
			}
		}

		public override void Unbind(EffectCommonProfile args)
		{
			base.Unbind(args);
			GL.Disable(EnableCap.Texture2D);
		}

		public common_color_or_texture_typeTexture Collada
		{
			get
			{
				return (common_color_or_texture_typeTexture)(((common_color_or_texture_type)rawNode).Item);
			}
		}
	}
}